import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import dts from "vite-plugin-dts";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    react(),
    dts({
      // 插件配置选项
      insertTypesEntry: true, // 是否在项目中生成 types.d.ts 入口文件
      // rollupTypes: true,
      exclude: ["node_modules/**", "src/app.tsx", "src/main.tsx"], // 排除不需要打包的文件夹或文件夹下的文件夹，如src/app/global.d.ts
    }),
  ],
  server: {
    host: "0.0.0.0",
    hmr: {
      clientPort: 443,
    },
    port: 1010,
  },
  define: {
    // "process.env": process.env,
    
    "process.env": {
      TARO_PLATFORM: "web",
      // 其他环境变量可以在这里添加
    },
    "global": {},
    DEPRECATED_ADAPTER_COMPONENT: false,

  },
  resolve: {
    alias: {
      // 这里配置 @ 指向 src 目录
      "@": "/src",
    },
  },
  build: {
    // minify: "esbuild",
    lib: {
      entry: "src/package/index.ts", // 指定入口文件
      name: "d8dTarojsTaroWeb", // 指定全局变量名
      formats: [
        // "es",
        "umd",
        // "cjs",
      ],
    },
    rollupOptions: {
      external: ["react", "react-dom", ],
      output: {
        dir: "dist",
        entryFileNames: `index.[format].js`,
        chunkFileNames: `index.[format].js`,
        assetFileNames: `index.[ext]`,
        globals: {
          react: "React",
          "react-dom": "ReactDOM",
   
        },
      },
    },
  },
});
